package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.bank.Bank;
import com.acme.bankapp.domain.client.Client;
import com.acme.bankapp.domain.client.Gender;
import com.acme.bankapp.domain.exceptions.ClientExistsException;
import com.acme.bankapp.domain.exceptions.NotEnoughFundsException;
import com.acme.bankapp.domain.exceptions.OverdraftLimitExceededException;


public class BankApplication {
	public static void main(String[] args) {
		BankService bankService = new BankService();
		Bank bank = bankService.createBank();
		Client ron = bankService.createClient("Ron", Gender.MALE);
		Client harry = bankService.createClient("Harry", Gender.MALE);
		Client hermione = bankService.createClient("Hermione", Gender.FEMALE);
		try {
			bankService.addClient(bank, ron);
		} catch (ClientExistsException e) {
			System.out.println(e.getMessage());
		}
		try {
			bankService.addClient(bank, hermione);
		} catch (ClientExistsException e) {
			System.out.println(e.getMessage());
		}
		try {
			bankService.addClient(bank, harry);
		} catch (ClientExistsException e) {
			System.out.println(e.getMessage());
		}
		bankService.addAccount(ron, bankService.createSavingAccount(10.d));
		bankService.addAccount(hermione, bankService.createCheckingAccount(20d, 100d));
		bankService.addAccount(harry, bankService.createCheckingAccount(100.d, 10d));
		modifyBank(bank);
		bankService.printMaximumAmountToWithdraw(bank);
		printBalance(bank);
	}
	
	private static void modifyBank(Bank bank) {
		bank.getClient(1).getAccount().deposit(10.0);
		try {
			bank.getClient(2).getAccount().withdraw(14.0);
		} catch (OverdraftLimitExceededException e) {
			System.out.println(e.getMessage());
		} catch (NotEnoughFundsException e) {
			System.out.println(e.getMessage());
		}
	}
	
	private static void printBalance(Bank bank) {
		for (Client client : bank.getClients()) {
			System.out.println(client);
		}
	}
}
